import React from "react";
import {NoticeIconTabProps} from "@/components/NoticeIcon/NoticeList";

export type WrapAuthProps = {

  authority?: string;
  children?: React.ReactElement<NoticeIconTabProps>[];
}

const WrapAuth = (props?: any) => {
  const handleAuth = (id?: string) => {
    //localStorage.getItem
    const menujson = localStorage.getItem('antd-menus');
    // 数据格式 {"buttons":["1","2"]}  1 2是 authority =>按钮的标识
    /*
     <WrapAuth authority = "222">
            <button>哈哈</button>
          </WrapAuth>
     */
    console.log(menujson)
    if (menujson != null) {
      const menuData = JSON.parse(menujson);
      console.log(menuData)
        const { buttons } = menuData;
        return buttons.includes(id);
    }
    return false;
  }
  const { authority, children } = props;
  return handleAuth(authority) ? {...children} : null;
};

export default WrapAuth;
